//
//  SortMoreViewController.m
//  MountEverestFM
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "SortMoreViewController.h"
#import "SortMoreTableViewCell.h"
#import "SortMoreXiangTableViewCell.h"
#import "SortMoreCollectionViewCell.h"
#import "SortMoreCollectionTwoViewCell.h"
#import "SortMoreCollectionThreeViewCell.h"
#import "MusicListViewController.h"
@interface SortMoreViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic ,strong)UICollectionView *collectionView;
@property (nonatomic ,strong)UICollectionViewFlowLayout *flowLayout;
@property (nonatomic ,strong)NSMutableDictionary *dic;
@property (nonatomic ,strong)NSMutableArray *arr;
@property (nonatomic ,strong)NSMutableArray *arr1;
@property (nonatomic ,strong)NSMutableArray *arr2;

@end

@implementation SortMoreViewController

-(void)netWorking
{
        [NetWorkManager GET:[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=%@&device=iPhone&pageId=1&pageSize=20&position=0&status=0&tagName=%@&title=%@",self.strId,self.str1,self.str] isCaChe:YES resultData:^(id responseObject) {
        
        self.dic=responseObject;
        self.arr=[self.dic objectForKey:@"list"];
        [self.collectionView reloadData];
    } resultRrror:^(NSError *error) {
        
    }];
    
}
-(void)netWorking1
{
    [NetWorkManager GET:[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=recent&categoryId=%@&device=iPhone&pageId=1&pageSize=20&position=0&status=0&tagName=%@&title=%@",self.strId,self.str1,self.str] isCaChe:YES resultData:^(id responseObject) {
        
        
        self.arr1=[responseObject objectForKey:@"list"];
        [self.collectionView reloadData];
    } resultRrror:^(NSError *error) {
        
    }];
    
}
-(void)netWorking2
{
    [NetWorkManager GET:[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=mostplay&categoryId=%@&device=iPhone&pageId=1&pageSize=20&position=0&status=0&tagName=%@&title=%@",self.strId,self.str1,self.str] isCaChe:YES resultData:^(id responseObject) {
        
        
        self.arr2=[responseObject objectForKey:@"list"];
        [self.collectionView reloadData];
    } resultRrror:^(NSError *error) {
        
    }];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self netWorking];
    [self netWorking1];
    [self netWorking2];
    
//    self.view.backgroundColor=[UIColor redColor];
     self.flowLayout=[[UICollectionViewFlowLayout alloc]init];

    //每个cell的大小
    self.flowLayout.itemSize =CGSizeMake(FM_Screen_Width, FM_Screen_Height-64);
    
    //cellectionView的滚动方向
    _flowLayout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    
    //最小的行间距
    _flowLayout.minimumLineSpacing=0;
    
  
    
    self.collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, FM_Screen_Width, FM_Screen_Height-64) collectionViewLayout:_flowLayout];
    self.collectionView.scrollEnabled=NO;
    self.collectionView.delegate=self;
    self.collectionView.dataSource=self;
    
    self.collectionView.pagingEnabled=YES;
    
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[SortMoreCollectionViewCell class] forCellWithReuseIdentifier:@"suibian"];
    [self.collectionView registerClass:[SortMoreCollectionTwoViewCell class] forCellWithReuseIdentifier:@"suibian1"];
    [self.collectionView registerClass:[SortMoreCollectionThreeViewCell class] forCellWithReuseIdentifier:@"suibian2"];
   

    
    
    
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item==0) {
        SortMoreCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"suibian" forIndexPath:indexPath];
        
        void(^block1)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(0,0);
                   };
        void(^blockMj1)(void)=^(void){
            [self netWorking];
        };

        cell.blockMj1=blockMj1;
        cell.block1=block1;
        
        void(^block2)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width, 0);
        
        };
        cell.block2=block2;
        
        void(^block3)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width*2, 0);
         
        };
        cell.block3=block3;
      
        void(^blockdian)(NSMutableDictionary *dic )=^(NSMutableDictionary *dic){
            MusicListViewController *mu=[[MusicListViewController alloc]init];
            mu.musicListDic  = dic;
            [self.navigationController pushViewController:mu animated:YES];
        
        };
        cell.blockdian=blockdian;
        
        cell.arr=self.arr;
        [cell.tableView reloadData];
        
        return cell;
 
    }else if (indexPath.item==1){
        
        SortMoreCollectionTwoViewCell *cell1=[collectionView dequeueReusableCellWithReuseIdentifier:@"suibian1" forIndexPath:indexPath];
        
        void(^block1)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(0, 0);
            
        };
        cell1.block11=block1;
        
        void(^block2)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width, 0);
            
        };
        cell1.block21=block2;
        
        void(^block3)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width*2, 0);
            
        };
        cell1.block31=block3;
        void(^blockdian1)(NSMutableDictionary *dic )=^(NSMutableDictionary *dic){
            MusicListViewController *mu=[[MusicListViewController alloc]init];
            mu.musicListDic  = dic;
            [self.navigationController pushViewController:mu animated:YES];
            
        };
        cell1.blockdian1=blockdian1;

        cell1.arr1=self.arr1;
    
        [cell1.tableView1 reloadData];
        
        return cell1;

    }else{
        SortMoreCollectionThreeViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"suibian2" forIndexPath:indexPath];
        
        void(^block1)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(0, 0);
            
        };
        cell.block111=block1;
        
        void(^block2)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width, 0);
            
        };
        cell.block222=block2;
        
        void(^block3)(void)=^(void){
            self.collectionView.contentOffset=CGPointMake(FM_Screen_Width*2, 0);
            
        };
        cell.block333=block3;
        void(^blockdian2)(NSMutableDictionary *dic )=^(NSMutableDictionary *dic){
            MusicListViewController *mu=[[MusicListViewController alloc]init];
            mu.musicListDic  = dic;
            [self.navigationController pushViewController:mu animated:YES];
            
        };
        cell.blockdian2=blockdian2;

        cell.arr=self.arr2;
        [cell.tableView reloadData];
        
        return cell;

    }
    return NULL;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
